//
//  LYDevelopEx.swift
//  kemiBear
//
//  Created by 李扬 on 2017/4/18.
//  Copyright © 2017年 李扬. All rights reserved.
//

import UIKit

enum LYScreenType {
    case normal
    case plus
    case ipx
    case se
    case small
}

final class LYDevelopEx: NSObject {

    static let shared = LYDevelopEx()

    private override init() {
        super.init()
        p_refreshData()
    }

    private(set) var screenWidth: CGFloat = 1
    private(set) var screenHeight: CGFloat = 1
    private(set) var screenWidthRatio: CGFloat = 1
    private(set) var screenHeightRatio: CGFloat = 1
    private(set) var isIphonex = false
    private(set) var screenType = LYScreenType.normal

    private func p_refreshIfNeeded() {
//        guard UIScreen.main.bounds.size.equalTo(CGSize(width: screenWidth, height: screenHeight)) else {
//            self.p_refreshData()
//            return
//        }
    }

    //  默认参考size = (375,667)
    private let designSize = CGSize.init(width: 375, height: 667)

    private func p_refreshData() {
        screenWidth = UIScreen.main.bounds.size.width
        screenHeight = UIScreen.main.bounds.size.height
        screenWidthRatio = screenWidth / designSize.width
        screenHeightRatio = screenHeight / designSize.height

        let deviceSize = UIScreen.main.bounds.size
        let ipxSizes = [CGSize.init(width: 375, height: 812),
                        CGSize.init(width: 414, height: 896)]
        if ipxSizes.contains(deviceSize) {
            isIphonex = true
            screenType = .ipx
        } else if deviceSize.height == 736 {
            screenType = .plus
        } else if deviceSize.height == 568 {
            screenType = .se
        } else if deviceSize.height == 480 {
            screenType = .small
        }
    }

    var splashImage: UIImage? {
        switch screenType {
        case .normal:
            return UIImage(named: "ad_splashNormal")
        case .plus:
            return UIImage(named: "ad_splashPlus")
        case .ipx:
            return UIImage(named: "ad_splashX")
        case .se:
            return UIImage(named: "ad_splash5C")
        case .small:
            return UIImage(named: "ad_splashSmall")
        }
    }
}
